package com.yootk.servlet;

import com.yootk.vo.Dept;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/JSTLServlet2")
public class JSTLServlet2 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Dept> depts = new ArrayList<>();
        for (int x = 0; x < 3; x++) {
            Dept dept = new Dept();
            dept.setDeptno(1900L + x);
            dept.setDname("沐言科技教学部 - " + x);
            dept.setLoc("北京");
            depts.add(dept);
        }
        req.setAttribute("allDepts", depts); // 保存集合属性
        req.getRequestDispatcher("/2/test03.jsp").forward(req, resp); // 服务端跳转
    }
}
